package com.free.fs.controller;

import com.free.fs.common.utils.R;
import com.free.fs.model.FilePojo;
import com.free.fs.model.Score;
import com.free.fs.model.User;
import com.free.fs.service.UserService;
import com.free.fs.service.impl.ScoreServiceImpl;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ScoreController extends BaseController{

    @Autowired
    ScoreServiceImpl scoreService;

    @Autowired
    UserService userService;

    /**
     * 文件打分
     * @param score
     * @return
     */
    @RequiresPermissions("file:score")
    @PostMapping("/addScore")
    public R addScore(Score score){
        System.out.println("获取结果："+score);
        score.setUserId(getLoginUserId());
        if(scoreService.addScore(score)){

            return R.succeed("打分成功");
        }

        return R.failed("打分失败");
    }


    /**
     * 获取文件得分
     */
    @RequiresPermissions("file:check")
    @GetMapping("/getScore/{fileId}")
    public R getScore(@PathVariable Long fileId){
        Score score = scoreService.queryScoreByFId(fileId);
        return R.succeed(score,"查询成功");
    }

    /**
     * 获取上传者
     */
    @GetMapping("/getUploader/{fileId}")
    public String getUploader(@PathVariable Long fileId){
        Score score = scoreService.queryScoreByFId(fileId);
        User user = userService.getById(score.getUploaderId());
        return   user.getNickName() ;
    }



}
